const request = {
  /**
   * @function 检查输入的元素，并根据实体返回
   * @param {Object} params 用户输入的参数
   * @param {Object} entityName 实体的名字
   */
  checkParams (params, entityName) {
    let entity = require(`./entity/${entityName}`)
    let _OBJ = {}
    let _ERRLIST = []
    for (let i in entity) {
      if (entity[i].required && params[i] === undefined) {
        _ERRLIST.push(`${i} ${entity[i].name}不能为空`.toString())
      } else if (entity[i].like) {
        _OBJ = {..._OBJ, ...{[i]: `%${data}%?like`}}
      } else {
        let data = (params[i] === undefined || params[i] === '') ? entity[i].default === undefined ? '' : entity[i].default : params[i]
        _OBJ = {..._OBJ, ...{[i]: data}}
      }
    }
    return {error: _ERRLIST.length > 0, data: _ERRLIST.length > 0 ? _ERRLIST : _OBJ}
  }
}
module.exports = request;